<html>
<head><meta charset="utf-8"><title>Any plans on supporting inline wasm? · project-inline-asm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/index.html">project-inline-asm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F.html">Any plans on supporting inline wasm?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="208798819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Any%20plans%20on%20supporting%20inline%20wasm%3F/near/208798819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F.html#208798819">(Sep 02 2020 at 09:25)</a>:</h4>
<p>I just tried using asm! in a wasm project and got this error: <code>error[E0472]: asm! is unsupported on this target</code> I'm wondering if there are plans on supporting asm! for wasm?</p>



<a name="208830654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Any%20plans%20on%20supporting%20inline%20wasm%3F/near/208830654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F.html#208830654">(Sep 02 2020 at 14:20)</a>:</h4>
<p>It's theoretically possible. There aren't concrete plans. LLVM's support for inline wasm is rather quirky.</p>



<a name="208830725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Any%20plans%20on%20supporting%20inline%20wasm%3F/near/208830725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F.html#208830725">(Sep 02 2020 at 14:21)</a>:</h4>
<p>Is there anything that you need asm for that you can't achieve with the intrinsics in <code>std::arch</code>?</p>



<a name="208837028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Any%20plans%20on%20supporting%20inline%20wasm%3F/near/208837028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F.html#208837028">(Sep 02 2020 at 14:59)</a>:</h4>
<p><span class="user-mention silent" data-user-id="143274">Amanieu</span> <a href="#narrow/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F/near/208830725">said</a>:</p>
<blockquote>
<p>Is there anything that you need asm for that you can't achieve with the intrinsics in <code>std::arch</code>?</p>
</blockquote>
<p>Yes, reading a global defined in another module, for example.</p>



<a name="208837208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Any%20plans%20on%20supporting%20inline%20wasm%3F/near/208837208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F.html#208837208">(Sep 02 2020 at 15:00)</a>:</h4>
<p>I'm not familiar with wasm, how would that look like in asm? Can't you do it with <code>extern</code>?</p>



<a name="208837393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Any%20plans%20on%20supporting%20inline%20wasm%3F/near/208837393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F.html#208837393">(Sep 02 2020 at 15:01)</a>:</h4>
<p>The story is a bit complicated, but basically the other module that defines the global is not generated by LLVM and is not statically or dynamically linkable. It just has a global and exports it, directly, without following linking conventions.</p>



<a name="208837463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Any%20plans%20on%20supporting%20inline%20wasm%3F/near/208837463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F.html#208837463">(Sep 02 2020 at 15:01)</a>:</h4>
<p>wasm global != rust global. A wasm global is a single value that you can't get a reference to, but only access using <code>global.get</code> and <code>global.set</code>. It doesn't have a memory location, unlike rust globals.</p>



<a name="208837480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Any%20plans%20on%20supporting%20inline%20wasm%3F/near/208837480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F.html#208837480">(Sep 02 2020 at 15:01)</a>:</h4>
<p>If I could generate inline Wasm I'd just generate <code>global.read $blah</code>. I'd also need an import though.</p>



<a name="208837567"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Any%20plans%20on%20supporting%20inline%20wasm%3F/near/208837567" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F.html#208837567">(Sep 02 2020 at 15:02)</a>:</h4>
<p>I know <span class="user-mention" data-user-id="133247">@bjorn3</span> , that's why I need inline assembly to read it.</p>



<a name="208837616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Any%20plans%20on%20supporting%20inline%20wasm%3F/near/208837616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F.html#208837616">(Sep 02 2020 at 15:02)</a>:</h4>
<p>I was responding to <span class="user-mention silent" data-user-id="143274">Amanieu</span>.</p>



<a name="208839398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Any%20plans%20on%20supporting%20inline%20wasm%3F/near/208839398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F.html#208839398">(Sep 02 2020 at 15:13)</a>:</h4>
<p>I would prefer if this was possible to express with intrinsics, but if it's not possible then sure, we can have inline asm for wasm.</p>



<a name="208839464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Any%20plans%20on%20supporting%20inline%20wasm%3F/near/208839464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F.html#208839464">(Sep 02 2020 at 15:13)</a>:</h4>
<p>If you want to have a go at it, I suggest looking at the PR which adds NVPTX inline asm.</p>



<a name="208865399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Any%20plans%20on%20supporting%20inline%20wasm%3F/near/208865399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F.html#208865399">(Sep 02 2020 at 18:17)</a>:</h4>
<p>There are some really weird quirks about how LLVM's inline asm handles wasm, and in particular how it treats "registers".</p>



<a name="208865466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Any%20plans%20on%20supporting%20inline%20wasm%3F/near/208865466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F.html#208865466">(Sep 02 2020 at 18:17)</a>:</h4>
<p>And unlike other architectures, we couldn't just say "well, LLVM matches the conventions of the platform assembler so you can always use the platform assembler externally instead".</p>



<a name="208865487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Any%20plans%20on%20supporting%20inline%20wasm%3F/near/208865487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Any.20plans.20on.20supporting.20inline.20wasm.3F.html#208865487">(Sep 02 2020 at 18:17)</a>:</h4>
<p>If we're going to enable it, I think we'd need to very carefully insulate ourselves from LLVM's quirks.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>